/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.panomedic.kernel;

import com.panomedic.Constants;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

/**
 *
 * @author Yare
 */
public class Pref {
    
    private static Preferences prefs;
    
    private static Pref instance;
    
    public static void initDefaults() {
        try {

                prefs = Preferences.userRoot().node(Constants.defNodePath);
            if (! Preferences.userRoot().nodeExists(Constants.defNodePath)) {
                prefs.putInt(Constants.FRAME_X, 100);
                prefs.putInt(Constants.FRAME_Y, 100);
                prefs.putInt(Constants.FRAME_WIDTH, 800);
                prefs.putInt(Constants.FRAME_HEIGHT, 600);
                prefs.putInt(Constants.SPLIT_WIDTH, 200);
                
                // Options values
            }
                prefs.putInt(Constants.CS_TYPE, prefs.getInt(Constants.CS_TYPE, 1));
                prefs.putInt(Constants.COMP_PROC,  1);
                prefs.putInt(Constants.METHOD_CHOICE, prefs.getInt(Constants.METHOD_CHOICE, Constants.METHOD_LUT));
                prefs.putInt(Constants.LUT_ACCURACY, prefs.getInt(Constants.LUT_ACCURACY, 10));
                prefs.putInt(Constants.BLUR_RADIUS, prefs.getInt(Constants.BLUR_RADIUS, 0));
                
                prefs.putInt(Constants.SAVE_END, prefs.getInt(Constants.SAVE_END, 0));
                prefs.putInt(Constants.SMOOTHING, prefs.getInt(Constants.SMOOTHING, 0));
                prefs.putBoolean(Constants.MONOTON, prefs.getBoolean(Constants.MONOTON, false));
                
                prefs.flush();
        } catch (BackingStoreException ex) {
            Logger.getLogger(Kernel.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }

    public static void setCurrent() {
        prefs = Preferences.userRoot().node(Constants.defNodePath);
        
        prefs.putInt(Constants.FRAME_X, VisualHandler.getInstance().getFrame().getLocation().x);
        prefs.putInt(Constants.FRAME_Y, VisualHandler.getInstance().getFrame().getLocation().y);
        prefs.putInt(Constants.FRAME_HEIGHT, VisualHandler.getInstance().getFrame().getSize().height);
        prefs.putInt(Constants.FRAME_WIDTH, VisualHandler.getInstance().getFrame().getSize().width);
        prefs.putInt(Constants.SPLIT_WIDTH, VisualHandler.getInstance().getFrame().getSplitWidth());
        try {

//        int x = VisualHandler.getInstance().getFrame().getLocation().x;
//        int y = VisualHandler.getInstance().getFrame().getLocation().y;
//        System.out.println(x+","+y);
            prefs.flush();
        } catch (BackingStoreException ex) {
            ex.printStackTrace();
        }
    }
    
//    public static void saveOptions() {
//        prefs = Preferences.userRoot().node(Constants.defNodePath);
//        
//        prefs.putInt(Constants.CS_TYPE, 10);
//        prefs.putInt(Constants.COMP_PROC, 7);
//        prefs.putInt(Constants.METHOD_CHOICE, Options.METHOD_LUT);
//        prefs.putInt(Constants.LUT_ACCURACY, 10);
//        prefs.putInt(Constants.BLUR_RADIUS, 10);
//        
//    }
    
    public static void printAll() {
        prefs = Preferences.userRoot().node(Constants.defNodePath);
        String[] keys;
        try {
            keys = prefs.keys();
            for (String key : keys) {
                System.err.println("key: " + key);
            }
        } catch (BackingStoreException ex) {
            ex.printStackTrace();
        }
        
    }
    
    
    
}
